package com.ja.openchat.viewmodels;

import android.app.Application;

import androidx.annotation.NonNull;

import com.zy.openchat.core.manager.TgEvent;
import com.zy.openchat.core.model.call.CallManager;
import com.zy.openchat.core.model.user.UserInfo;
import com.ja.openchat.ui.chat.call.C2CCallActivity;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import me.goldze.mvvmhabit.base.BaseModel;
import me.goldze.mvvmhabit.base.BaseViewModel;


public class C2CActivityViewModel extends BaseViewModel {

    private C2CCallActivity mContext;

    public C2CActivityViewModel(@NonNull Application application, BaseModel mRepository) {
        super(application);
    }


    public void setContext(C2CCallActivity mContext) {
        this.mContext = mContext;
    }


    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onTgEvent(final TgEvent tg_event) {
        switch (tg_event.event) {
            case EUser_Td_Contact_Photo_Ok: {
                UserInfo user = (UserInfo) tg_event.data;
                if (user.id == CallManager.getCallManager().c2cUserId()) {
                    mContext.resetC2CUserUI();
                }
            }
            break;
            case EUser_Call_State_Changed: {
                if (CallManager.getCallManager().isInCalling()) {
                    mContext.resetCallUI();
                } else {//通话已结束
                    finish();
                }
            }
            break;
            case EUser_Headset_State_Changed: {
                mContext.resetSpeakerBtn();
            }
            break;
            case EUser_Refresh_Call_Time: {
                mContext.resetCallingTime();
            }
            break;
            case EUser_Call_Local_Voice_Mute_Changed: {
                mContext.changeAudioMute();
            }
            break;
        }
    }

}
